package cn.sz.hy.ui.frame;

import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.swt.SWT;

import cn.sz.hy.common.EventBus;
import cn.sz.hy.common.Globel;
import cn.sz.hy.ui.widget.top.FileIOWidget;

import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.GridData;
import cn.sz.hy.ui.widget.top.ExecuteBox;
import com.swtdesigner.SWTResourceManager;

public class TopPanel extends Composite {

	private final FormToolkit toolkit = new FormToolkit(Display.getCurrent());
	private FileIOWidget src1;
	private FileIOWidget src2;
	private FileIOWidget det;
	private ExecuteBox executeBox;

	/**
	 * Create the composite.
	 * 
	 * @param parent
	 * @param style
	 */
	public TopPanel(Composite parent, int style) {
		super(parent, style);
		addDisposeListener(new DisposeListener() {
			public void widgetDisposed(DisposeEvent e) {
				toolkit.dispose();
			}
		});
		toolkit.adapt(this);
		toolkit.paintBordersFor(this);
		setLayout(new GridLayout(1, false));

		initSrc1();

		initSrc2();

		initDet();
		toolkit.adapt(det);
		toolkit.paintBordersFor(det);
		{
			executeBox = new ExecuteBox(this, SWT.NONE);
			toolkit.adapt(executeBox);
			toolkit.paintBordersFor(executeBox);
		}

	}

	private void initDet() {
		det = new FileIOWidget(this, SWT.NONE, Globel.DET);
		GridData gd_det = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
		gd_det.widthHint = 499;
		det.setLayoutData(gd_det);
		det.setButtonName("导出路径");
		det.setLabelName("导出路径设定：");
		EventBus.getInstance().addComponent(Globel.DET_TEXTFIELDE_ID, det.getText());
	}

	private void initSrc2() {
		src2 = new FileIOWidget(this, SWT.NONE, Globel.BACKUP);
		GridData gd_src2 = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1,
				1);
		gd_src2.widthHint = 499;
		src2.setLayoutData(gd_src2);
		src2.setButtonName("抽取文件导入");
		src2.setLabelName("抽取文件路径：");
		toolkit.adapt(src2);
		toolkit.paintBordersFor(src2);
	}

	private void initSrc1() {
		src1 = new FileIOWidget(this, SWT.NONE, Globel.MAIN);
		src1.setBackground(SWTResourceManager.getColor(SWT.COLOR_WIDGET_BACKGROUND));
		GridData gd_src1 = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1,
				1);
		gd_src1.widthHint = 499;
		src1.setLayoutData(gd_src1);
		src1.setButtonName("源文件导入");
		src1.setLabelName("源文件路径：");
		toolkit.adapt(src1);
		toolkit.paintBordersFor(src1);
	}
}
